import com.troyworks.framework.ui.DraggableClip;
import flash.display.BitmapData;
import flash.filters.DropShadowFilter;
/**
 * @author Troy Gardner
 */
class com.troyworks.framework.ui.DragProxy extends MovieClip{// DraggableClip {
	public var xOffset:Number = 0;
	public var yOffset:Number = 0;
	private static var instance : DragProxy;
	public var proxyImage:MovieClip;
	public var currentClip:MovieClip;
	public var ghostImage:BitmapData; 
	private var isLoaded : Boolean = false;
	
	/**
	 * @return singleton instance of DragProxy
	 */
	public static function getInstance() : DragProxy {

		return instance;
	}
	
	public function DragProxy() {
		trace("new ProxyImage");
		instance = this;
	}
	public function setDragSource(_mc:MovieClip):Void{
		currentClip = _mc;
		trace("setDragSource " + _mc._name + " " + isLoaded);
		var bounds:Object = _mc.getBounds(_mc);
		xOffset = _mc._xmouse-bounds.xMin;
		yOffset = _mc._ymouse-bounds.yMin;
		trace("xOffset " + xOffset + " yOffset " + yOffset);
		updatePosition();
		ghostImage = new BitmapData(_mc._width, _mc._height, true);
		trace("w " + ghostImage.width + " h " + ghostImage.height);
		trace("proximage " + proxyImage);
		
		proxyImage.attachBitmap(null, 2);
		proxyImage.attachBitmap(ghostImage, 2);
		var ds:DropShadowFilter = new DropShadowFilter(10,45,0x000000,20);
		proxyImage.filters = [ds];
		ghostImage.draw(_mc);
	//	_visible = true;
	}
	public function onLoad():Void{
		trace("DragProxy.onLoad");
		proxyImage= createEmptyMovieClip("proxyImage", getNextHighestDepth());	
		
		isLoaded = true;
		_alpha = 60;
	
	}
	function onMouseMove():Void{
		updatePosition();
	}
	function updatePosition():Void{
	//	trace("updatePosition");
		_x = _parent._xmouse - xOffset;
		_y = _parent._ymouse- yOffset;
	}
	public function releaseDragSource(releaseMC : MovieClip) : Void {
			trace("DragProxy.releaseDragSource");
			ghostImage.dispose();
		//		proxyImage.addProperty()
		//		_visible = false;
	}

}